import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from "path";
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import requireTransform from 'vite-plugin-require-transform'
import prerender from "vite-plugin-prerender";
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  // CDN地址
  // base: "https://yqjimli.cn/webAI",
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    prerender({
      staticDir: resolve(__dirname, "dist"),
      routes: [
        "/3D-Generator",
        "/studio"
      ],
    }),
    requireTransform({
      fileRegex: /.mjs$|.vue$/,
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  build: {
    // 解决 Element Plus 打包问题
    commonjsOptions: {
      include: [/node_modules/],
    },
    rollupOptions: {
      output: {
        manualChunks: {
          'element-plus': ['element-plus'],
        },
      },
    },
  },
})